<?php

namespace app\worker;

use app\auto\CreateStoreAccount;
use think\worker\Server;
use Workerman\Lib\Timer;

class Http extends Server
{
    protected $socket = 'http://0.0.0.0:2380';
    protected static $heartbeat_time = 55;

    protected $uidConnections = array();

    public function init()
    {
        $this->worker->name = "fh-4s";
    }

    public function onConnect($connection)
    {
        echo("connect....\n");
    }

    public function reconnect($connection)
    {
        $connection->reconnect();
        $connection->onConnect = function ($con) {
            echo "重连成功\n";
        };
        $connection->onError = function ($con, $code, $msg) {
            echo "重连失败，错误码：$code 错误信息：$msg\n";
        };
    }

    public function onWorkerStart($worker)
    {
        //定时任务
        Timer::add(1, function () use ($worker) {
//            $worker->send("hello world");
//            echo "定时任务\n";
//            app(CreateStoreAccount::class)->createAccount();
        });
    }
}